package top.szhome.develop.generator;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

/**
 * 文件节点
 *
 * @author 唐加利
 * @date 2023/9/6
 **/
@Data
public class FileNode implements Comparable<FileNode>{

    /**
     * 构造文件节点
     * @param path
     * @param name
     */
    public FileNode(String path, String name) {
        this.path = path;
        this.name = name;
        this.children = new LinkedList<>();
        this.leaf = false;
        this.key = UUID.randomUUID().toString();
    }

    private String key;

    /**
     * 上级节点
     */
    private String path;

    /**
     * 节点名称
     */
    private String name;

    /**
     * 是否叶子节点
     */
    private boolean leaf;

    /**
     * 节点内容，只有叶子节点可以有内容
     */
    private String content;

    /**
     * 子节点集合
     */
    private List<FileNode> children;

    @Override
    public int compareTo(FileNode o) {
        if(leaf && !o.leaf){
            return 1;
        }

        if(!leaf && o.leaf){
            return -1;
        }

        return name.compareToIgnoreCase(o.name);
    }
}
